<!DOCTYPE HTML>
<html>
<head>
<title>MenuGetHandle() | AutoHotkey</title>
<meta name="description" content="The MenuGetHandle function retrieves the Win32 menu handle of a menu." />
<meta name="ahk:equiv-v2" content="objects/Menu.htm#Handle" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>MenuGetHandle() <span class="ver">[v1.1.23+]</span></h1>

<p>获取菜单的 <a href="Menu.htm#Win32_Menus">Win32 菜单</a>句柄.</p>
<pre class="Syntax">Handle := <span class="func">MenuGetHandle</span>(MenuName)</pre>

<h2>参数</h2>
<dl>

  <dt>MenuName</dt>
  <dd><p>已存在的菜单名称. 菜单名称不区分大小写.</p></dd>

</dl>

<h2 id="Remarks">备注</h2>
<p>返回的句柄仅在 Win32 菜单被销毁前有效. 一旦菜单被销毁, 操作系统会将该句柄重新分配给后续由脚本或其他程序创建的任一菜单. 会触发菜单被销毁的条件列于 <a href="Menu.htm#Win32_Menus">Win32 菜单</a>下方.</p>

<h2>相关</h2>
<p><a href="Menu.htm">Menu</a>, <a href="MenuGetName.htm">MenuGetName()</a></p>

<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>Menu MyMenu, Add, Item 1, no
Menu MyMenu, Add, Item 2, no
Menu MyMenu, Add, Item B, no

<em>; 获取菜单内菜单项的数目.</em>
item_count := DllCall("GetMenuItemCount", "ptr", MenuGetHandle("MyMenu"))

<em>; 获取最后一个菜单项的ID.</em>
last_id := DllCall("GetMenuItemID", "ptr", MenuGetHandle("MyMenu"), "int", item_count-1)

MsgBox, MyMenu has %item_count% items, and its last item has ID %last_id%.

no:
return
</pre>
</div>

</body>
</html>